package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author wxh
 * @since 2024-09-01
 */
@Api(tags = "优惠券相关接口")
@RestController
@RequestMapping("/coupons")
@RequiredArgsConstructor
public class CouponController {

    private final ICouponService couponService;

    /**
     * 新增优惠券
     *
     * @param couponFormDTO
     */
    @ApiOperation("新增优惠券")
    @PostMapping
    public void addCoupon(@Valid @RequestBody CouponFormDTO couponFormDTO) {
        couponService.addCoupon(couponFormDTO);
    }

    /**
     * 分页查询优惠券
     *
     * @param query
     * @return
     */
    @GetMapping("/page")
    public PageDTO<CouponPageVO> pageQueryConpon(CouponQuery query) {
        return couponService.pageQueryConpon(query);

    }

    /**
     * 优惠券发放
     *
     * @param couponIssueFormDTO
     */
    @ApiOperation("优惠券发放")
    @PutMapping("/{id}/issue")
    public void beginIssue(@Valid @RequestBody CouponIssueFormDTO couponIssueFormDTO) {
        couponService.beginIssue(couponIssueFormDTO);
    }


    @GetMapping("/list")
    @ApiOperation("查询发放中的优惠券")
    public List<CouponVO> queryIssueCoupons() {
        return couponService.queryIssueCoupons();
    }
}
